package ink.metoo.auto.fishpi.chatroom.command

import ink.metoo.auto.fishpi.chatroom.Message

interface Command {

    val commandText: String

    val alias: Array<String>
        get() = arrayOf()

    val commandTypes: Array<Type>
        get() = arrayOf(Type.SELF_CLIENT, Type.OTHER_CLIENT)

    fun isMatch(message: Message) = arrayOf(*alias, commandText).findLast {
        message.md?.startsWith(it) ?: false
    } != null

    fun execute(message: Message)

    val Message.commandParams: List<String>
        get() = md?.split(regex = "[ \n]".toPattern()) ?: emptyList()

    enum class Type {

        /**
         * 自己客户端能使用
         */
        SELF_CLIENT,

        /**
         * 其他客户端能使用
         */
        OTHER_CLIENT,


    }
}